{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c934ea9b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1679282058,39c20e97-9ece-4c80-8c9c-3e09e630e273', 'time_used': 439, 'confidence': 59.191, 'thresholds': {'1e-3': 62.327, '1e-4': 69.101, '1e-5': 73.975}, 'faces1': [{'face_token': '089e9d59ff99800544e7f91b32aeb77d', 'face_rectangle': {'top': 473, 'left': 374, 'width': 200, 'height': 200}}], 'faces2': [{'face_token': '5cb96e79dc90ce327f2fe054bae0fed9', 'face_rectangle': {'top': 514, 'left': 268, 'width': 414, 'height': 414}}], 'image_id1': 'J9dFAzJVaJMl04ZQ1k0sYw==', 'image_id2': 'zDhrj6jeiE7QJkaK3Vg9/g=='}\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸比对\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/compare\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f_01 = open('xzq.jpg', 'rb')\n",
    "f_02 = open('ckk.jpg', 'rb')\n",
    "img_01 = base64.b64encode(f_01.read())\n",
    "img_02 = base64.b64encode(f_02.read())\n",
    "\n",
    "# 2. 酬载准备\n",
    "params ={\n",
    "    \"api_key\":\"fQfBhzqD4IFg-XpYsfNrtQMj-V_xQnZ6\",\n",
    "    \"api_secret\":\"IOBHCcpHCKbXX98_5sUYf2Uh62qF3YpM\",\n",
    "    \"image_base64_1\":img_01,\n",
    "    'image_base64_2':img_02,\n",
    "}\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
